<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2013 H2 Group. Multiple-Licensed under the H2 License, Version 1.0,
and under the Eclipse Public License, Version 1.0
(http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Architecture
</title><link rel="stylesheet" type="text/css" href="stylesheet.css" />
<!-- [search] { -->
<script type="text/javascript" src="navigation.js"></script>
</head><body onload="highlight()" onscroll="scroll()">

<table class="nav" onmousemove="return mouseMove(event)"><tr class="nav"><td class="nav" valign="top">
<div id = "searchMenu" style="width: 180px; overflow: hidden;">
<div class="menu" style="white-space:nowrap;">
<img src="images/h2-logo-2.png"
    alt="H2 database logo"
    onclick="document.location='main.html'"
    width="136" height="74"/> &nbsp;&nbsp;<span id = "goTop" onclick="window.scrollTo(0,0)" style="color: #fff; position:fixed; font-size: 20px; cursor: pointer;">&#x25b2;</span> </div>

<form action="submit" onsubmit="return goFirst();">
<table width="100%" class="search">
    <tr class="search">
        <td class="search" colspan="2">
<!-- translate
<a href="http://translate.google.com/translate?u=http%3A%2F%2Fh2database.com"
    onclick="javascript:startTranslate();return false;">Translate</a>
<div id = "translate" style="display:none"><div id = "google_translate_element"></div></div>
translate -->
        </td>
    </tr>
    <tr class="search">
        <td class="search" colspan="2">
        <b><label for="search">Search:</label></b>
        </td>
    </tr>
    <tr class="search">
        <td class="search" colspan="2">
            <input id = "search" name="search" type="text" size="16" maxlength="100" onkeyup="listWords(this.value, '')" /><br />
            <input type="reset" id = "clear" style="display:none;" value="Clear" onclick="listWords('', '');" />
        </td>
    </tr>
    <tr class="search" style="display:none;" >
        <td class="search" style="width: 1%; vertical-align: middle;">
            <input id = "highlight" type="checkbox" checked="checked" onclick="highlightCurrent(this.checked, search.value)" />
        </td>
        <td class="search" style="width: 99%; padding: 0px; vertical-align: middle;">
            <label for="highlight">Highlight keyword(s)</label>
        </td>
    </tr>
    <tr class="search">
        <td class="search" colspan="2">
            <table id = "result" style="border: 0px;">
                <tr style="display:none"><td></td></tr>
            </table>
        </td>
    </tr>
</table>
</form>
<div class="menu">
<b><a href="main.html">Home</a></b><br />
<a href="download.html">Download</a><br />
<a href="cheatSheet.html">Cheat Sheet</a><br />
<br />
<b>Documentation</b><br />
<a href="quickstart.html">Quickstart</a><br />
<a href="installation.html">Installation</a><br />
<a href="tutorial.html">Tutorial</a><br />
<a href="features.html">Features</a><br />
<a href="performance.html">Performance</a><br />
<a href="advanced.html">Advanced</a><br />
<br />
<b>Reference</b><br />
<a href="grammar.html">SQL Grammar</a><br />
<a href="functions.html">Functions</a><br />
<a href="datatypes.html">Data Types</a><br />
<a href="../javadoc/index.html">Javadoc</a><br />
<a href="../h2.pdf">PDF (1 MB)</a><br />
<br />
<b>Support</b><br />
<a href="faq.html">FAQ</a><br />
<a href="sourceError.html">Error Analyzer</a><br />
<a href="http://groups.google.com/group/h2-database">Google Group (English)</a><br />
<a href="http://groups.google.co.jp/group/h2-database-jp">Google Group (Japanese)</a><br />
<a href="http://groups.google.com/group/h2-cn">Google Group (Chinese)</a><br />
<br />
<b>Appendix</b><br />
<a href="history.html">History &amp; Roadmap</a><br />
<a href="license.html">License</a><br />
<a href="build.html">Build</a><br />
<a href="links.html">Links</a><br />
<a href="jaqu.html">JaQu</a><br />
<a href="mvstore.html">MVStore</a><br />
<br />

</div>
</div>
</td>

<td class="nav" style="cursor: e-resize;" onmousedown="return mouseDown(event)" onmouseup="return mouseUp(event)">&nbsp;</td>
<td class="nav"><div class="content">

<!-- } -->

<h1>Architecture</h1>
<a href="#introduction"> Introduction</a><br />
<a href="#top_down"> Top-down overview</a><br />
<a href="#jdbc"> JDBC driver</a><br />
<a href="#connection"> Connection/session management</a><br />
<a href="#command"> Command execution and planning</a><br />
<a href="#table"> Table/index/constraints</a><br />
<a href="#transaction"> Undo log, redo log, and transactions layer</a><br />
<a href="#btree"> B-tree engine and page-based storage allocation</a><br />
<a href="#filesystem"> Filesystem abstraction</a><br />

<h2 id="introduction">Introduction</h2>
<p> H2 implements an embedded and standalone ANSI-SQL89 compliant SQL engine on top of a B-tree based disk store. </p>
<p> As of October 2013, Thomas is still working on our next-generation storage engine called MVStore. This will in time replace the B-tree based storage engine. </p>

<h2 id="top_down">Top-down Overview</h2>
<p> Working from the top down, the layers look like this: <ul><li>JDBC driver. </li><li>Connection/session management. </li><li>SQL Parser. </li><li>Command execution and planning. </li><li>Table/Index/Constraints. </li><li>Undo log, redo log, and transactions layer. </li><li>B-tree engine and page-based storage allocation. </li><li>Filesystem abstraction. </li></ul>
</p>

<h2 id="jdbc">JDBC Driver</h2>
<p> The JDBC driver implementation lives in <code>org.h2.jdbc, org.h2.jdbcx</code> </p>

<h2 id="connection">Connection/session management</h2>
<p> The primary classes of interest are: <table class="main">
<tr><th>Package</th><th>Description</th></tr>
<tr><td>org.h2.engine.Database</td><td>the root/global class</td></tr>
<tr><td>org.h2.engine.SessionInterface</td>
    <td>abstracts over the differences between embedded and remote sessions</td></tr>
<tr><td>org.h2.engine.Session</td>
    <td>local/embedded session</td></tr>
<tr><td>org.h2.engine.SessionRemote</td>
    <td>remote session</td></tr>
</table>
</p>

<h2 id="jdbc">Parser</h2>
<p> The parser lives in <code>org.h2.command.Parser</code>. It uses a straightforward recursive-descent design. </p>
<p> See Wikipedia <a href="http://en.wikipedia.org/wiki/Recursive_descent_parser">Recursive-descent parser</a> page. </p>


<h2 id="command">Command execution and planning</h2>
<p> Unlike other databases, we do not have an intermediate step where we generate some kind of IR (intermediate representation) of the query. The parser class directly generates a command execution object. Then we run some optimisation steps over the command to possibly generate a more efficient command. The primary packages of interest are: <table class="main">
<tr><th>Package</th><th>Description</th></tr>
<tr><td>org.h2.command.ddl</td><td>Commands that modify schema data structures</td></tr>
<tr><td>org.h2.command.dml</td><td>Commands that modify data</td></tr>
</table>
</p>

<h2 id="table">Table/Index/Constraints</h2>
<p> One thing to note here is that indexes are simply stored as special kinds of tables. </p>
<p> The primary packages of interest are: <table class="main">
<tr><th>Package</th><th>Description</th></tr>
<tr><td>org.h2.table</td><td>Implementations of different kinds of tables</td></tr>
<tr><td>org.h2.index</td><td>Implementations of different kinds of indices</td></tr>
</table>
</p>

<h2 id="transaction">Undo log, redo log, and transactions layer</h2>
<p> We have a transaction log, which is shared among all sessions. See also http://en.wikipedia.org/wiki/Transaction_log http://h2database.com/html/grammar.html#set_log </p>
<p> We also have an undo log, which is per session, to undo an operation (an update that fails for example) and to rollback a transaction. Theoretically, the transaction log could be used, but for simplicity, H2 currently uses it's own "list of operations" (usually in-memory). </p>
<p> With the MVStore, this is no longer needed (just the transaction log). </p>

<h2 id="btree">B-tree engine and page-based storage allocation.</h2>
<p> The primary package of interest is <code>org.h2.store</code>. </p>
<p> This implements a storage mechanism which allocates pages of storage (typically 2k in size) and also implements a b-tree over those pages to allow fast retrieval and update. </p>

<h2 id="filesystem">Filesystem abstraction.</h2>
<p> The primary class of interest is <code>org.h2.store.FileStore</code>. </p>
<p> This implements an abstraction of a random-access file. This allows the higher layers to treat in-memory vs. on-disk vs. zip-file databases the same. </p>

<!-- [close] { -->
</div></td></tr></table>
<script type="text/javascript" src="index.js"></script>
<script type="text/javascript" src="search.js"></script>
<script type="text/javascript">
function startTranslate() {
    document.getElementById('translate').style.display='';
    var script=document.createElement('script');
    script.setAttribute("type","text/javascript");
    script.setAttribute("src", "http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit");
    document.getElementsByTagName("head")[0].appendChild(script);
}
function googleTranslateElementInit() {
    new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
</script>

<!-- } --><!-- analytics --></body></html>
